<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <h2 class="text-center  margin-bottom">{{title}}</h2>
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :md="8" :sm="24">
                        <a-form-item label="收运时间">
                            <a-range-picker
                                    :placeholder="['开始时间', '结束时间']"
                                    v-model="rangeTime"
                                    format="YYYY-MM-DD"
                                    @change="handleDateChange"
                            />
                        </a-form-item>
                    </a-col>

                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <span class="table-page-search-submitButtons">
                              <a-button type="primary" @click="searchQuery" icon="search">
                                  查询数据列表
                              </a-button>
                        </span>
                    </a-col>

                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- table区域-begin -->
        <div>
            <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    class="j-table-force-nowrap"
                    @change="handleTableChange"
            >
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="link" slot-scope="text,record">
                    <a href="#" @click="handleShowDetail(record)">
                        <span style="color: #3fe4f1">{{text}}</span>
                        <span style="color: #3fe4f1;text-decoration:underline;margin-left: 5px;" >
                            详情
                        </span>
                    </a>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="text" height="25px" alt style="width: auto;height: 50px;"/>
                </template>
            </a-table>
        </div>

        <in-storage-static-details ref="detailsRef" ></in-storage-static-details>
    </a-card>
</template>

<script>
    /**
     * create by Jane
     */
    import '@/assets/less/TableExpand.less'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import InStorageStaticDetails from './modules/InStorageStaticDetails'

    export default {
        components: { InStorageStaticDetails },
        mixins: [JeecgListMixin],
        data() {
            return {
                title : '废物入库记录',
                // 表头
                columns: [],
                url: {
                    list: '/hc/hcStorage/list',
                },
                rangeTime:[],
                queryParam: {
                    creatTimeBegin: null,
                    creatTimeEnd: null,
                    customerName: '',
                },
            }
        },
        created() {
        },
        methods: {
            async initDictConfig() {
                // 获取到用户登陆的信息
                let userInfo = this.$store.getters.userInfo;
                if(userInfo.companysId){
                    this.queryParam.companysId = userInfo.companysId;
                }

                this.queryParam.creatTimeBegin = new Date().MonthFirstDay()
                this.queryParam.creatTimeEnd = new Date().MonthLastDay()
                this.rangeTime = [this.queryParam.creatTimeBegin, this.queryParam.creatTimeEnd]

                this.setColumns()
            },
            handleDateChange(value, dateString) {
                this.rangeTime = dateString
                if (dateString[0]) {
                    this.queryParam.creatTimeBegin = dateString[0]
                }
                if (dateString[1]) {
                    this.queryParam.creatTimeEnd = dateString[1]
                }
            },

            setColumns() {
                this.columns = [
                    {
                        title: '序号',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function(t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '入库编号',
                        align: 'center',
                        dataIndex: 'storage',
                        scopedSlots: { customRender: 'link' },
                    },
                    {
                        title: '废物类型',
                        align: 'center',
                        dataIndex: 'wasteTypeName',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '废物净重',
                        align: 'center',
                        dataIndex: 'wastePresentValue',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: function(value, row, index) {
                            const obj = {
                                children: <span style = 'font-weight:600;font-size:18px;' >{value ? `${value} ${row.priceUnit || 'KG'}` : ''}</span>,
                                attrs: {}
                            }
                            return obj
                        }
                    },
                    {
                        title: '废物毛重',
                        align: 'center',
                        dataIndex: 'wasteOriginalValue',
                        customRender: function(value, row, index) {
                            return  value ? `${value} ${row.priceUnit || 'KG'}` : ''
                        }
                    },
                    {
                        title: '废物皮重',
                        align: 'center',
                        dataIndex: 'wasteTareValue',
                        customRender: function(value, row, index) {
                            return  value ? `${value} ${row.priceUnit || 'KG'}` : ''
                        }
                    },
                    {
                        title: '入库人',
                        align: 'center',
                        dataIndex: 'operator',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '车牌号',
                        align: 'center',
                        dataIndex: 'carNumber',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    },
                    {
                        title: '入库时间',
                        align: 'center',
                        dataIndex: 'createTime',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    }
                ]
            },
            searchQuery: function() {
                this.loadData(1)
            },
            // 根据机构编号查询机构超时提交信息详情
            handleShowDetail : function(row) {
                if(row){
                    let ref = this.$refs.detailsRef;
                    if(ref){
                        ref.show(row);
                    }
                }
            },
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
